// --------------编辑页面弹出后获取用户的详细信息------------------
let id = new URLSearchParams(location.search).get('id');
let form = layui.form
    // console.log(id);
function renderEdit() {
    $.ajax({
        url: `admin/users/${id}`,
        success: function(res) {
            console.log(res);
            // 数据回填
            form.val('edit_form', res.data)
        }
    })
}
renderEdit()

//---------------点击立即提交,提交数据---------------
$('#edit_form').on('submit', function(e) {
    e.preventDefault()

    let data = $(this).serialize()
        // console.log(data);
    $.ajax({
        url: 'admin/users',
        type: 'PUT',
        data: data,
        success: function(res) {
            // console.log(res);
            if (res.status === 0) {
                layer.alert('修改成功', function(index) {
                    location.href = '../../../user/user.html'
                    layer.close(index);
                });
            }
        }

    })
})


//------------------重置-------------------

$('#reset_btn').on('click', function(e) {
    e.preventDefault()
    renderEdit()
})